﻿using UnityEngine;

public abstract class CircleArea : MonoBehaviour
{
    public abstract float Xmin { get; }
    public abstract float Xmax { get; }
    public abstract float Zmin { get; }
    public abstract float Zmax { get; }
    public abstract float Xwidth { get; }
    public abstract float Zwidth { get; }

    internal void Update()
    {
        var pos = transform.position;

        if (pos.x > Xmax)
        {
            pos.x -= Xwidth;
            transform.position = pos;
            OnChange();
        }
        if (pos.x < Xmin)
        {
            pos.x += Xwidth;
            transform.position = pos;
            OnChange();
        }

        if (pos.z > Zmax)
        {
            pos.z -= Zwidth;
            transform.position = pos;
            OnChange();
        }
        if (pos.z < Zmin)
        {
            pos.z += Zwidth;
            transform.position = pos;
            OnChange();
        }
    }

    protected virtual void OnChange()
    {

    }
}